package com.qzsoft.zhjd.asphalt.modules.asphaltalarm.controller;

import java.util.Map;

import com.qzsoft.zhjd.asphalt.modules.asphaltalarm.service.AsphaltAlarmService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.asphalt.modules.asphaltalarm.dto.AsphaltAlarmCountDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltalarm.dto.AsphaltAlarmHandlerDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltalarm.dto.AsphaltAlarmHandlerEditDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltalarm.dto.AsphaltAlarmListDto;
import com.qzsoft.zhjd.common.enums.BizCode;
import com.qzsoft.zhjd.common.utils.RenExceptionUtils;
import com.qzsoft.zhjd.common.utils.ResultUtils;

/**
 * @ClassName AsphaltAlarmController
 * @Description 预警信息控制器
 * @author linhuawei
 * @since 2021-11-26
 */
@RestController
@RequestMapping("/api/asphaltAlarm")
public class AsphaltAlarmController {

    @Autowired
    private AsphaltAlarmService asphaltAlarmService;

    /**
     * @Title page
     * @Description 获取预警信息分页列表
     * @param params 查询条件
     * @return 预警信息分页列表
     */
    @RequiresPermissions("api:asphaltalarm:page")
    @GetMapping("/page")
    public Result<IPage<AsphaltAlarmListDto>> page(@RequestParam Map<String, Object> params) {
        IPage<AsphaltAlarmListDto> page = asphaltAlarmService.pageDto(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title count
     * @Description 统计预警信息
     * @param params 查询条件
     * @return 预警信息
     */
    @RequiresPermissions("api:asphaltalarm:page")
    @GetMapping("/count")
    public Result<AsphaltAlarmCountDto> count(@RequestParam Map<String, Object> params) {
        AsphaltAlarmCountDto data = asphaltAlarmService.countDto(params);
        return ResultUtils.ok(data);
    }

    /**
     * @Title handler
     * @Description 预警处理
     * @param id 预警主键
     * @return 预警信息
     */
    @RequiresPermissions("api:asphaltalarm:handler")
    @GetMapping("/handler/{id}")
    public Result<AsphaltAlarmHandlerDto> handler(@PathVariable("id") String id) {
        AsphaltAlarmHandlerDto data = asphaltAlarmService.handler(id);
        if (null == data) {
            RenExceptionUtils.throwEx(BizCode.PARAMS_ERROR, "预警信息不存在");
        }
        return ResultUtils.ok(data);
    }

    /**
     * @Title handlerEdit
     * @Description 预警处理
     * @param entity 处理数据
     * @return 处理结果
     */
    @RequiresPermissions("api:asphaltalarm:handler")
    @PostMapping("/handlerEdit")
    public Result<String> handlerEdit(@RequestBody @Validated AsphaltAlarmHandlerEditDto entity) {
        asphaltAlarmService.handlerEdit(entity);
        return ResultUtils.ok();
    }

}
